home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Chess / Fly_Chess.jar / MatchForm.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-08-23  |  3.1 KB  |  79 lines

  1. import javax.microedition.lcdui.Command;
  2. import javax.microedition.lcdui.CommandListener;
  3. import javax.microedition.lcdui.Display;
  4. import javax.microedition.lcdui.Displayable;
  5. import javax.microedition.lcdui.Image;
  6. import javax.microedition.lcdui.List;
  7.  
  8. public class MatchForm implements CommandListener, ChessDisplayable {
  9.    private ChessLogic chesslogic = null;
  10.    private ChessDisplayable chessreturn = null;
  11.    private List myScreen;
  12.    private Command OKCommand;
  13.    private Command backCommand;
  14.  
  15.    public MatchForm(String var1, ChessLogic var2, ChessDisplayable var3) {
  16.       this.chesslogic = var2;
  17.       this.chessreturn = var3;
  18.       this.initialize(var1);
  19.    }
  20.  
  21.    public void commandAction(Command var1, Displayable var2) {
  22.       if (var1 != this.OKCommand && var1 != List.SELECT_COMMAND) {
  23.          if (var1 == this.backCommand) {
  24.             this.chessreturn.makeCurrent(CU.getDisplay());
  25.          }
  26.  
  27.       } else {
  28.          this.myScreen.setTitle("Making match, wait");
  29.          ChessGame var3 = this.chesslogic.getChessGame();
  30.          if (var3.postActive()) {
  31.             MessageForm var4 = new MessageForm("Making match", "Please wait", this);
  32.             var4.makeCurrent(CU.getDisplay());
  33.          } else {
  34.             this.match(this.myScreen.getString(this.myScreen.getSelectedIndex()));
  35.          }
  36.  
  37.       }
  38.    }
  39.  
  40.    private void initialize(String var1) {
  41.       this.myScreen = new List("Match", 3);
  42.       this.OKCommand = new Command("OK", 4, 1);
  43.       this.backCommand = new Command("Back", 2, 1);
  44.       StringTokenizer var2 = new StringTokenizer(var1, " 1234567890+-\t\n\r\f");
  45.       String var3 = "";
  46.  
  47.       while(var2.hasMoreElements() && !var3.equals("players")) {
  48.          var3 = (String)var2.nextElement();
  49.          if (!var3.equals("players") && !var3.equals(CU.getUserName())) {
  50.             this.myScreen.append(var3, (Image)null);
  51.          }
  52.       }
  53.  
  54.       this.myScreen.addCommand(this.OKCommand);
  55.       this.myScreen.addCommand(this.backCommand);
  56.    }
  57.  
  58.    public void makeCurrent(Display var1) {
  59.       var1.setCurrent(this.myScreen);
  60.       this.myScreen.setCommandListener(this);
  61.    }
  62.  
  63.    private boolean match(String var1) {
  64.       ChessGame var3 = this.chesslogic.getChessGame();
  65.       StringTokenizer var4 = new StringTokenizer(var1, " 1234567890+-:^.(\t\n\r\f");
  66.  
  67.       String var2;
  68.       try {
  69.          var2 = (String)var4.nextElement();
  70.       } catch (Exception var5) {
  71.          CU.shout("error in playername");
  72.          return false;
  73.       }
  74.  
  75.       var3.doPost("match " + var2 + " 30 30", true);
  76.       return true;
  77.    }
  78. }
  79.